<?php
/**
 * Description of UserQuestionWidget
 *
 * @author Alexey
 */
class UserQuestionWidget extends CWidget {

    public $userId = null;

    public $count;

    public $mode = "";

    public function init()
    {
        parent::init();
    }

    public function run()
    {
        if ($userId == null && $this->mode == "main-page")
        {
            $models = QuestionFacade::getLatesQuestion($this->count);
            $modelsCount = QuestionFacade::getQuestionCount();
        }
        else
        {
            $models = QuestionFacade::getLatesUserQuestion($this->userId, $this->count);
            $modelsCount = QuestionFacade::getQuestionCountByUser($this->userId);
        }
        if (!$modelsCount)
        {
            return;
        }
        $this->render('userQuestionView',
            array('models'     => $models,
                  'modelsCount' => $modelsCount,
                  'mode'    => $this->mode
            ));
    }
}
?>
